﻿var ViewController = function () {
    this.displayModelStateError = function (viewModel, responseJSON) {
        if (responseJSON == null) {
            var id = "errorList";
            if (viewModel.errorElementLower != null) {
                id = viewModel.errorElementLower.id;
            }

            if (document.getElementById(id) != null) {
                $("#" + id).empty();
            }
        }
        else {
            var resultHtml = pageController.processErrorToHtml(responseJSON);
            {
                var id = "errorList";
                if (viewModel.errorElement != null) {
                    id = viewModel.errorElement.id;
                }

                if (document.getElementById(id) != null) {
                    $("#" + id).empty();
                    $("#" + id).append("<div><ul>" + resultHtml + "</ul></div>");
                }
            }
            {
                var id = "errorListLower";
                if (viewModel.errorElementLower != null) {
                    id = viewModel.errorElementLower.id;
                }

                if (document.getElementById(id) != null) {
                    $("#" + id).empty();
                    $("#" + id).append("<div><ul>" + resultHtml + "</ul></div>");
                }
            }
        }
    }

    this.processErrorToHtml = function (responseJSON) {
        var message = "";
        $.each(responseJSON.ModelState, function (i, fieldItem) {
            $.each(fieldItem, function (j, errItem) {
                message += "<li>" + errItem.toString() + "</li>";
            });
        });
        return (message);
    }

    this.displayError = function (viewModel, errorHtml) {

    }

    this.padCharacters = function (num, places, character) {
        var zero = places - num.toString().length + 1;
        return Array(+(zero > 0 && zero)).join(character) + num;
    }
};
